import Axios from '@/util/ajax'
import MyMsg from "../../util/myMessage";

const state = {
    sexList:[],
    showEdit: false,
    empId: -1,
    isViewEmp: true,
    canEditUserId: false
};

const mutations = {
    Hide_Edit_Emp_Section: (state) => {
        state.showEdit = false
    },

    Init_Add_Emp_Page: (state) => {
        state.empId = -1;
        state.showEdit = true;
        state.isViewEmp = false;
        state.canEditUserId = true;
    },

    Init_Edit_Emp_Page: (state, data) => {
        //console.log("emp: ", data);
        //Object.assign(state.emp, data);
        state.empId = data;
        state.showEdit = true;
        state.isViewEmp = false;
        state.canEditUserId = false;
    },

    Init_View_Emp_Page: (state, data) => {
        state.emp = data;
        state.showEdit = true;
        state.isViewEmp = true;
        state.canEditUserId = false;
    },

    /*Update_Birth: (state, data) => {
        state.emp.birth = data
    }*/
};

const actions = {

    async fetchDropdownValues({state}){
        console.log("fetchDropdownValues");
        let res = await Axios.get("/hr/emp/init", {});
        state.sexList = res.result.sexList;
    },

    async addEmp({state}, emp){
        await Axios.post("/hr/emp", emp);
        //MyMsg.success("创建");
    },

    async editEmp({state}, emp){
        console.log("editEmp", emp);
        await Axios.put("/hr/emp", emp);
    },

};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}
